<?php
function GetColumnNames($table, $showerr) {
    include "connect.php";
    $sql = "(SELECT * FROM ".$table." LIMIT 0,1)";
    $response = mysql_query($sql);
    
    $i=0;
    while($i < mysql_num_fields($response)) {
        $meta = mysql_fetch_field($response,$i);
        $column[$i] = $meta->name;
        $i++;
    }
    
    if(!$response AND $showerr) {
        echo "<p class=sql_error>SQL > ".mysql_error()."</p>";
    }
    mysql_close();
    return $column;
}

// TODO: Find a better way to do this:
function GetKeyFieldName($table) {
    switch($table) {
    case 'clients': 
        return 'clientID';
    case 'suppliers':
        return 'supplierID';
    case 'items':
        return 'itemID';
    case 'sales':
        return 'salesID';
    case 'purchases':
        return 'purchaseID';
    case 'facilities':
        return 'facilityID';
    case 'itemStock':
        return 'stockID';
    case 'itemsPurchased':
        return 'ipurchaseID';
    case 'itemsSold':
        return 'isalesID';
    default:
        return '';
    }
}
?>